package com.example.shop.service.impl;

import com.example.shop.domain.Goods;
import com.example.shop.mapper.GoodsMapper;
import com.example.shop.service.GoodsService;
import com.example.shop.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @projectName: travel
 * @package: com.example.travel.service.impl
 * @className: UserService
 * @author: Liqian
 * @description: TODO
 * @date: 2024/4/11 9:07
 * @version: 1.0
 */

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> selectList() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        return goodsMapper.select(id);
    }

    @Override
    public List<Goods> selectAllByName(String name) {
        return goodsMapper.selectAllByName(name);
    }

    @Override
    public List<Goods> selectByName(String name) {
        // 进行模糊查询，name 不为 null 或空字符串时执行
        return goodsMapper.selectByName(name);
    }


    @Override
    public void add(Goods goods) {
        Map<String, Object> map = ThreadLocalUtil.get();
        goods.setUserId((Integer) map.get("id"));

//        Outlay outlay1 =new Outlay();
//        outlay1.setAmount(outlay.getAmount());
//        outlay1.setRemark(outlay.getRemark());
//        outlay1.setChannelId(outlay.getChannelId());
//        outlay1.setCategoryId(outlay.getCategoryId());
//        System.out.println(outlay.getCategoryId());

        goodsMapper.insert(goods);
    }


    @Override
    public List<Goods> selectById(Goods goods) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        goods.setUserId(id);
        return goodsMapper.selectListById(goods);
    }

    @Override
    public List<Goods> selectOne(Goods goods) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        goods.setUserId(id);
        return goodsMapper.selectOneById(goods);
    }

    @Override
    public int delete(Goods goods) {
        return goodsMapper.deleteById(goods);
    }

    @Override
    public void update(Goods goods) {
        goodsMapper.updateById(goods);
    }




}
